#include <stdio.h>
#include "matrix.h"
#include "includes.h"
int main(int argc, char *argv[])
{
   FILE *IN, *OUT;
   unsigned int g_instancias;
   int i,ret;
   unsigned int x,y,z;
   Matrix *A;
   Matrix *B;
   char Operacao='n';

   IN=fopen(argv[1],"r");
   OUT=fopen(argv[2],"w");

   if (IN==NULL)
   {
       printf("Could not open file for reading.\n");
   }
   else
   {
       fprintf(stdout,"Success opening file.\n\n");
       fscanf(IN,"%u",&g_instancias);

       for(i=0;i<g_instancias; i++)
       {
           A=(Matrix*) malloc(sizeof(Matrix));
           if(!A)
            puts("vacilo");
           B=(Matrix*) malloc(sizeof(Matrix));
           if(!B)
            puts("vacilo");
           fscanf(IN,"%u %u %u",&x,&y,&z);//tamanho da matri

           ret=newMatrix(A,x,y,z);
           ret=newMatrix(B,x,y,z);
           printf("matrix OP No. %i\n",i);
           ret=fillMatrix(IN,A);//preenche A
           printf("matrix A\n");
           ret=printMatrix(*A);

           while(Operacao!='=')
           {
                ret=getNewOperator(IN,&Operacao);
                switch(Operacao)
                {
                    case '+':
                        ret=fillMatrix(IN,B);//preenche b
                        ret=MatrixAdd (A, *B);
                        break;
                    case '-':
                        ret=fillMatrix(IN,B);//preenche b
                        ret=MatrixAdd (A, *B);
                        break;
                    case '=':
                    ret=printMatrix(*A);
                        break;
                }

           }//dealoc A e B
            DeleteMatrix(B);
            free(B);
            DeleteMatrix(A);
            free(A);
            Operacao='n';
       }
      /* do not pass a NULL pointer to fclose() */
       fclose(IN);
       fclose(OUT);
   }
   return 0;
}
